package dfa;

import fa.FARule;

import java.util.List;

/**
 * @author haoly
 * @title DFARulebook
 * @date 2025/4/16 10:58
 * @description DFARulebook
 */
public class DFARulebook<T> {
    private final List<FARule<T>> rules;

    public DFARulebook(List<FARule<T>> rules) {
        this.rules = rules;
    }

    public T nextState(T state, Character character){
        FARule<T> rule = ruleFor(state, character);
        if (rule != null) {
            return rule.follow();
        }
        return null;
    }

    private FARule<T> ruleFor(T state, Character character) {
        for (FARule<T> rule : rules) {
            if (rule.appliesTo(state, character)) {
                return rule;
            }
        }
        return null;
    }


}
